﻿
// Remember to invoke within jQuery(window).load(...)
// If you don't, Jcrop may not initialize properly
jQuery(window).load(function() {

    jQuery('#originalImage').Jcrop({

    onChange: showPreview,
    onSelect: showPreview,
    aspectRatio: 1
       
      
    });

    // Patch for IE to force "overflow: auto;"
    document.getElementById("imgContainer").style["position"] = "relative";

});

// Our simple event handler, called from onChange and onSelect
// event handlers, as per the Jcrop invocation above
function showPreview(coords) {

    // value for cropping
    showCoords(coords);
    
    if (parseInt(coords.w) > 0) {
        var rx = 128 / coords.w;
        var ry = 128 / coords.h;

        jQuery('#preview').css({
        width: Math.round(rx * $('#newFileWidth').val()) + 'px',
        height: Math.round(ry * $('#newFileHight').val()) + 'px',
            marginLeft: '-' + Math.round(rx * coords.x) + 'px',
            marginTop: '-' + Math.round(ry * coords.y) + 'px'
        });
    }

   
}

// pass value for cropping image
function showCoords(c) {
    $('#x1').val(c.x);
    $('#y1').val(c.y);
    $('#x2').val(c.x2);
    $('#y2').val(c.y2);
    $('#w').val(c.w);
    $('#h').val(c.h);
};

function ValidateSelected() {
    if (document.getElementById("w").value == "" || document.getElementById("w").value == "0"
        || document.getElementById("h").value == "" || document.getElementById("h").value == "0") {
        alert("No area to crop was selected");
        return false;
    }
}